package com.xxxt.wx;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxt.dao.ClassGradeMapper;
import com.xxxt.dao.CollegeMapper;
import com.xxxt.dao.CompanyMapper;
import com.xxxt.dao.GradeMapper;
import com.xxxt.dao.PracticeMapper;
import com.xxxt.dao.SchoolMapper;
import com.xxxt.dao.SpecialtyMapper;
import com.xxxt.dao.StudentMapper;
import com.xxxt.dao.TeacherMapper;
import com.xxxt.entity.ClassGrade;
import com.xxxt.entity.College;
import com.xxxt.entity.Comment;
import com.xxxt.entity.Company;
import com.xxxt.entity.Feedback;
import com.xxxt.entity.Grade;
import com.xxxt.entity.Inform;
import com.xxxt.entity.Practice;
import com.xxxt.entity.School;
import com.xxxt.entity.Specialty;
import com.xxxt.entity.Student;
import com.xxxt.entity.Summarize;
import com.xxxt.entity.Teacher;
import com.xxxt.hrs.service.StudentService;
import com.xxxt.jxj.service.CommentService;
import com.xxxt.utils.CheckcodeUtil;
import com.xxxt.utils.MD5Util;
import com.xxxt.utils.MailUtil;
import com.xxxt.utils.TokenUtil;
import com.xxxt.wsc.service.PracticeService;
import com.xxxt.wsc.service.SummarizeService;
import com.xxxt.zpc.service.CommonService;
import com.xxxt.zpc.service.CompanyService;
import com.xxxt.zpc.service.FeedbackService;
import com.xxxt.zpc.service.InformService;

/**
 * @description:微信端的需要查询数据库的接口
 * @author:wsc
 * @date:2020年6月10日 下午11:18:42
 */
@RestController
@RequestMapping("/wx/")
public class WechatQueryController {
	@Autowired
	private CommonService commonService;

	@Autowired
	SummarizeService summarizeService;

	@Autowired
	PracticeService practiceService;

	@Autowired
	private InformService informService;

	@Autowired
	private FeedbackService feedbackService;

	@Autowired
	private StudentService studentService;

	@Autowired
	private StudentMapper studentMapper;

	@Autowired
	private ClassGradeMapper classGradeMapper;

	@Autowired
	private TeacherMapper teacherMapper;

	@Autowired
	CompanyService companyService;

	@Autowired
	private CommentService commentService;

	@Autowired
	private GradeMapper gradeMapper;
	@Autowired
	private SpecialtyMapper specialtyMapper;
	@Autowired
	private CollegeMapper collegeMapper;
	@Autowired
	private SchoolMapper schoolMapper;
	@Autowired
	PracticeMapper practiceMapper;
	@Autowired
	private CompanyMapper companyMapper;
	/*
	 * 登录 ********
	 */
	@PostMapping(value = "login", produces = "application/json;charset=UTF-8")
	public JSONObject login(@RequestBody Map<String, String> map, HttpServletRequest request,
			HttpServletResponse response) {
		JSONObject json = new JSONObject();
		HttpSession session = request.getSession(false);
		if (session != null) {
			session.invalidate();
		}
		String userName = map.get("userName");
		String password = map.get("password");
		// 全新的session
		session = request.getSession(true);
		// 状态码
		int status = 1;
		// 提示信息
		String message = "账号或密码不正确";
		// 职位
		String position = null;
		// 名字
		String name = null;
		// 账号
		String account = null;

		try {
			if (userName != null && password != null && !userName.equals("") && !password.equals("")) {
				password = MD5Util.md5withkey(password, "xxxt");
				Student student = null;
				student = commonService.studentLogin(userName, password, session);
				if (student != null) {
					// 此次登录是学生登录
					status = 0;
					message = "登陆成功";
					position = "student";
					name = student.getName();
					account = student.getSno();

					response.setHeader("Authorization", TokenUtil.sign(student.getName(), student.getSno()));
					json.put("status", status);
					json.put("message", message);
					json.put("position", position);
					json.put("name", name);
					json.put("account", account);
					return json;
				} else {
					Teacher teacher;
					teacher = commonService.teacherLogin(userName, password, session);
					if (teacher != null) {
						// 此次是老师登录
						if (teacher.getRegisterStatus().equals("agree")) {
							status = 0;
							message = "登陆成功";
							position = "teacher";
							name = teacher.getName();
							account = teacher.getTno();

							response.setHeader("Authorization", TokenUtil.sign(teacher.getName(), teacher.getTno()));
							json.put("status", status);
							json.put("message", message);
							json.put("position", position);
							json.put("name", name);
							json.put("account", account);
							return json;
						} else {
							message = "该账号还没有审核通过";
							status = 2;
							json.put("status", status);
							json.put("message", message);
							return json;
						}
					}
				}
			} else {
				status = 3;
				message = "账号密码不能为空";
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", message);
			return json;
		}
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 退出
	 */
	@PostMapping("loginOut")
	@ResponseBody
	public JSONObject loginOut(HttpSession session) {
		JSONObject json = new JSONObject();
		int status = -1;
		// 提示信息
		String message = "操作失败，请重试！";
		try {
			// 销毁session
			session.invalidate();
			status = 200;
			message = "退出成功";
		} catch (Exception e) {
			e.printStackTrace();
		}
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	// TODO 实习记录
	// 通过学号获取学生实习记录列表
	@GetMapping("student-get-practicelist")
	public JSONObject queryPracticeListBySno(HttpSession session, String sno) {
		JSONObject json = new JSONObject();
		int status = 0;
		String message = "操作成功";
		List<Practice> list = null;
		try {
			list = practiceService.queryPracticeListBySno(sno);
			json.put("list", list);
			json.put("status", status);
			json.put("message", message);
			return json;
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "操作失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
	}
	
	// 判断是否填写有入职登记但是没有填写离职登记的
	@GetMapping("isRecord")
	public JSONObject isRecord(HttpSession session,String sno) {

		JSONObject json = new JSONObject();
		int status = 0;	
		String message = "查询成功";
		if(sno==null) {
			sno = (String) session.getAttribute("account");
		}
		try {
			boolean b = practiceService.isRecord(sno);
			if(b) {
				List<Practice> list = practiceMapper.queryPracticeListBySno(sno,"is null",null);
				Practice practice = list.get(0);
				json.put("practiceId", practice.getPracticeId());
				json.put("entryTime", practice.getEntryTime());
				json.put("isRecord", 0);
				json.put("status", status);
				json.put("message", "已填写过入职登记");
				return json;
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "操作失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		json.put("isRecord", 1);
		json.put("practiceId", null);
		json.put("entryTime", null);
		json.put("status", status);
		json.put("message", "尚未填写入职登记");
		return json;
	}

	//通过学号和公司编号来判断是否在改公司就职过
	@GetMapping("isJob")
	public JSONObject isRecord(HttpSession session, String sno, String companyId) {

		JSONObject json = new JSONObject();
		int status = 0;
		String message = "在该公司就职过";
		if (sno == null) {
			sno = (String) session.getAttribute("account");
		}
		try {
			boolean b = practiceService.isJob(sno, companyId);
			if(b) {
				json.put("status", status);
				json.put("message", message);
				return json;
			}else {
				status = 1;
				message = "未在该公司就职过";
				json.put("status", status);
				json.put("message", message);
				return json;
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "操作失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
	}

	@GetMapping("isRecordLeave")
	public JSONObject isRecordLeave(String practiceId) {

		JSONObject json = new JSONObject();
		int status = 0;
		String message = "已填写离职登记";
		boolean b;
		try {
			b = practiceService.isRecordLeave(practiceId);
			if(b) {
				json.put("status", status);
				json.put("message", message);
				return json;
			}else {
				status = 1;
				message = "未填写离职登记";
				json.put("status", status);
				json.put("message", message);
				return json;
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "操作失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		
	}
	// 通过实习编号id获取单个实习记录具体内容
	@SuppressWarnings("unchecked")
	@GetMapping("getPracticeInfo")
	public JSONObject queryPracticeInfoById(String practiceId) {
		JSONObject json = new JSONObject();
		int status = 0;
		String message = "操作成功";

		try {
			Map<String, Object> map = practiceService.queryPracticeInfoById(practiceId);
			Practice practice = (Practice) map.get("practice");
			List<String> entryTestify = (List<String>) map.get("entryTestify");
			List<String> leaveTestify = (List<String>) map.get("leaveTestify");
			json.put("practice", practice);
			json.put("entryTestify", entryTestify);
			json.put("leaveTestify", leaveTestify);
			json.put("status", status);
			json.put("message", message);
			return json;
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "操作失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
	}

	// 查询总结列表
	@GetMapping("getMonthlyReportList")
	public JSONObject getSummarizeList(String classGradeId, String commitTime, String sno, String summarizeType,
			HttpSession session) {
		JSONObject json = new JSONObject();
		int status = 0;
		String message = "查询成功";
		// String classGradeId = map.get("classGradeId");
		// String commitTime = map.get("commitTime");
		// String sno = map.get("sno");
		// String summarizeType = map.get("summarizeType");
		// 如果是学生登录了账号，查询自己的
		if (session.getAttribute("account") != null) {
			sno = (String) session.getAttribute("account");
		}
		List<Summarize> summarizeList;
		try {
			summarizeList = summarizeService.querySummarizeByOthers(classGradeId, commitTime, sno, summarizeType,null);
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "查询失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		json.put("status", status);
		json.put("message", message);
		json.put("summarizeList", summarizeList);
		return json;
	}

	// 查询总结信息
	@GetMapping("getMonthlyReportInfo")
	public JSONObject getSummarize(String id) {
		JSONObject json = new JSONObject();
		int status = 0;
		String message = "查询成功";
		Summarize summarize = null;
		try {
			summarize = summarizeService.querySummarizeById(id);
		} catch (Exception e) {
			e.printStackTrace();
			status = -1;
			message = "查询失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		json.put("status", status);
		json.put("message", message);
		json.put("summarize", summarize);
		return json;
	}

	/**
	 * @describe 根据学号查询单个学生
	 * @param sno
	 *            需要查询的学生学号
	 * @return
	 */
	@RequestMapping(value = "queryOneStudentBySno", method = RequestMethod.GET)
	public JSONObject queryOneStudentBySno(String sno, HttpSession session) {
		JSONObject json = new JSONObject();
		if (sno == null || "".equals(sno)) {
			json.put("status", 1);
			json.put("message", "传入数据不合法！");
			return json;
		}
		// 先查询此人是否存在
		boolean studentIsExist;
		try {
			studentIsExist = studentService.studentIsExist(sno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (studentIsExist == false) {
			json.put("status", 2);
			json.put("message", "此学生不存在！");
			return json;
		}
		// 进行查询
		Student queryOneStudentSchoolInfoBySno;
		try {
			queryOneStudentSchoolInfoBySno = studentMapper.queryOneStudentSchoolInfoBySno(sno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		json.put("status", 0);
		json.put("message", "操作成功");
		json.put("student", queryOneStudentSchoolInfoBySno);
		return json;
	}

	/**
	 * @describe 根据姓名模糊查询出学生有关信息
	 * @param name
	 * @return
	 */
	@RequestMapping(value = "queryManyStudentByNameLike", method = RequestMethod.GET)
	public JSONObject queryManyStudentByNameLike(String name, int pageNum, int pageSize) {
		JSONObject json = new JSONObject();
		if (name == null || "".equals(name)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		try {
			// name = map.get("name");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		PageInfo<Student> queryOneStudentByNameLikeWithPage;
		try {
			queryOneStudentByNameLikeWithPage = studentService.queryManyStudentByNameLikeWithPage(pageNum, pageSize,
					name);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneStudentByNameLikeWithPage.getSize() <= 0) {
			json.put("status", 2);
			json.put("message", "暂无查询结果！");
			return json;
		}
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryOneStudentByNameLikeWithPage);
		return json;
	}

	/**
	 * @describe 根据班级id查询该班级的所有学生集合
	 * @param classGradeId
	 *            需要查询的班级id
	 * @return
	 */
	@RequestMapping(value = "queryOneStudentByClassGrade", method = RequestMethod.GET)
	public JSONObject queryOneStudentByClassGrade(String classGradeId, int pageNum, int pageSize) {
		JSONObject json = new JSONObject();
		if (classGradeId == null || "".equals(classGradeId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 数据处理
		try {
			// classGradeId = map.get("classGradeId");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 根据班级id查询班级
		ClassGrade queryOneClassGradeByClassGradeId;
		try {
			queryOneClassGradeByClassGradeId = classGradeMapper.queryOneClassGradeByClassGradeId(classGradeId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneClassGradeByClassGradeId == null) {
			json.put("status", 2);
			json.put("message", "该班级不存在！");
			return json;
		}
		PageInfo<Student> queryOneClassGradeByClassGradeIdWithPage = studentService
				.queryClassGradeByClassGradeIdWithPage(pageNum, pageSize, classGradeId);
		if (queryOneClassGradeByClassGradeIdWithPage.getSize() <= 0) {
			json.put("status", 3);
			json.put("message", "该班级暂时没有学生！");
			return json;
		}
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryOneClassGradeByClassGradeIdWithPage);
		return json;
	}

	/**
	 * @describe 根据年级id查询该年级的所有学生集合然后分页显示
	 * @param pageNum
	 * @param pageSize
	 * @param classGrade
	 * @return
	 */
	@RequestMapping(value = "queryStudentByGrade", method = RequestMethod.GET)
	@ResponseBody
	public JSONObject queryStudentByGrade(int pageNum, int pageSize, String gradeId) {
		// 参数校验
		JSONObject json = new JSONObject();
		if (gradeId == null || "".equals(gradeId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 查询年级是否存在
		Grade selcetOneGradeByGradeId;
		try {
			selcetOneGradeByGradeId = gradeMapper.selcetOneGradeByGradeId(gradeId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (selcetOneGradeByGradeId == null) {
			json.put("status", 2);
			json.put("message", "该年级不存在！");
			return json;
		}
		// 去查询学生
		PageInfo<Student> queryStudentByGradeWithPage;
		try {
			queryStudentByGradeWithPage = studentService.queryStudentByGradeWithPage(pageNum, pageSize, gradeId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (queryStudentByGradeWithPage.getSize() <= 0) {
			json.put("status", 3);
			json.put("message", "该页数数据为空！");
			return json;
		}
		// 返回查询结果
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryStudentByGradeWithPage);
		return json;
	}

	/**
	 * @describe 根据专业id查询该专业的所有学生集合然后分页显示
	 * @param pageNum
	 *            第几页开始查询
	 * @param pageSize
	 *            一页显示的大小
	 * @param specialtyId
	 *            专业id
	 * @return
	 */
	@RequestMapping(value = "queryStudentBySpecialty", method = RequestMethod.GET)
	@ResponseBody
	public JSONObject queryStudentBySpecialty(int pageNum, int pageSize, String specialtyId) {
		// 参数校验
		JSONObject json = new JSONObject();
		if (specialtyId == null || "".equals(specialtyId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 查询专业是否存在
		Specialty selcetOneSpecialtyBySpecialtyId;
		try {
			selcetOneSpecialtyBySpecialtyId = specialtyMapper.selcetOneSpecialtyBySpecialtyId(specialtyId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (selcetOneSpecialtyBySpecialtyId == null) {
			json.put("status", 2);
			json.put("message", "该专业不存在！");
			return json;
		}
		// 查询
		PageInfo<Student> queryStudentBySpecialtyWithPage;
		try {
			queryStudentBySpecialtyWithPage = studentService.queryStudentBySpecialtyWithPage(pageNum, pageSize,
					specialtyId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (queryStudentBySpecialtyWithPage.getSize() <= 0) {
			json.put("status", 3);
			json.put("message", "该页数数据为空！");
			return json;
		}
		// 返回查询结果
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryStudentBySpecialtyWithPage);
		return json;
	}

	/**
	 * @describe 根据学院id查询该学院的所有学生集合然后分页显示
	 * @param pageNum
	 *            第几页开始查询
	 * @param pageSize
	 *            一页显示的大小
	 * @param collegeId
	 *            学院id
	 * @return
	 */
	@RequestMapping(value = "queryStudentByCollege", method = RequestMethod.GET)
	@ResponseBody
	public JSONObject queryStudentByCollege(int pageNum, int pageSize, String collegeId) {
		JSONObject json = new JSONObject();
		// 数据校验
		if (collegeId == null || "".equals(collegeId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 查询该学院
		College selcetOneCollegeByCollegeId;
		try {
			selcetOneCollegeByCollegeId = collegeMapper.selcetOneCollegeByCollegeId(collegeId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (selcetOneCollegeByCollegeId == null) {
			json.put("status", 2);
			json.put("message", "该学院不存在！");
			return json;
		}
		// 进行查询
		PageInfo<Student> queryStudentByCollegeWithPage;
		try {
			queryStudentByCollegeWithPage = studentService.queryStudentByCollegeWithPage(pageNum, pageSize, collegeId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (queryStudentByCollegeWithPage.getSize() <= 0) {
			json.put("status", 3);
			json.put("message", "该页数数据为空！");
			return json;
		}
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryStudentByCollegeWithPage);
		return json;
	}

	/**
	 * 
	 * @param pageNum
	 *            第几页开始查询
	 * @param pageSize
	 *            每页显示大小
	 * @param schoolId
	 *            学校id
	 * @return
	 */
	@RequestMapping(value = "queryStudentBySchool", method = RequestMethod.GET)
	@ResponseBody
	public JSONObject queryStudentBySchool(int pageNum, int pageSize, String schoolId) {
		JSONObject json = new JSONObject();
		// 参数校验
		if (schoolId == null || "".equals(schoolId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 查询该学校
		School selcetOneSchool;
		try {
			selcetOneSchool = schoolMapper.selcetOneSchool(schoolId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (selcetOneSchool == null) {
			json.put("status", 2);
			json.put("message", "该学校不存在！");
			return json;
		}
		// 进行分页
		PageInfo<Student> queryStudentBySchoolWithPage;
		try {
			queryStudentBySchoolWithPage = studentService.queryStudentBySchoolWithPage(pageNum, pageSize, schoolId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if (queryStudentBySchoolWithPage.getSize() <= 0) {
			json.put("status", 3);
			json.put("message", "该页数数据为空！");
			return json;
		}
		// 返回查询结果
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("studentList", queryStudentBySchoolWithPage);
		return json;
	}
	/**
	 * 
	 * 1.姓名有，其他空  根据姓名查学生

	  2.班级有，姓名有：根据姓名查该班级的学生
	  3.班级有，姓名无：根据班级id查这个班级学生

	  4.年级有，姓名有：根据姓名模糊查询该年级的学生
	  5.年级有，姓名无：根据年级id查询这个班级的学生

	  6.专业有，姓名有：根据姓名查询该专业的学生
	  7,专业有，姓名无：根据专业id查询所有学生

	  8.学院有，姓名有：根据姓名查询该需学院的学生	
	  9.学院有，姓名无：根据学院id查询该学院学生

	  10.学校有，姓名有：根据姓名查询该学校的学生
	  11.学校有，姓名无：根据学校id查询该学校学生
	  
	 * @param name 姓名
	 * @param classGradeId 班级id
	 * @param gradeId  年级id
	 * @param specialtyId 专业id
	 * @param collegeId 年级id
	 * @param schoolId 学校id
	 * @param pageSize 一页大小
	 * @param pageNum 从第几条开始
	 * @return
	 */
	@RequestMapping(value="queryManyStudentWithFactors" ,method = RequestMethod.GET)  
	@ResponseBody
	public JSONObject queryManyStudentWithFactors(String name,String classGradeId,String gradeId,String specialtyId,String collegeId,String schoolId,Integer pageSize,Integer pageNum) {
		JSONObject json=new JSONObject();
		//条件判断（不能都为空）：
		if((name==null||"".equals(name))&&(classGradeId==null||"".equals(classGradeId))&&
		(gradeId==null||"".equals(gradeId))&&(specialtyId==null||"".equals(specialtyId))&&
		(collegeId==null||"".equals(collegeId))&&(schoolId==null||"".equals(schoolId))&&(pageSize==null)&&(pageNum==null)) {
			json.put("status", 1);
			json.put("message", "传入数据不合法！");
			return json;
		}
		if("".equals(name)||"".equals(classGradeId)||"".equals(gradeId)||
		"".equals(specialtyId)||"".equals(collegeId)||"".equals(schoolId)||pageSize==null||pageNum==null) {
			json.put("status", 1);
			json.put("message", "传入数据不合法！");
			return json;
		}
		//除了名字，都为空——>根据名字查
		if(name!=null&&classGradeId==null&&gradeId==null&&specialtyId==null&&collegeId==null&&schoolId==null) {
			//根据名字进行模糊查询
			PageInfo<Student> queryManyStudentByNameLikeWithPage;
			try {
				queryManyStudentByNameLikeWithPage = studentService.queryManyStudentByNameLikeWithPage(pageNum, pageSize,
						name);
			} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
			}
			if(queryManyStudentByNameLikeWithPage.getSize()<=0) {
				//根据名字查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList", queryManyStudentByNameLikeWithPage);
				return json;
		}
		//姓名加班级(班级id和姓名不为空其他都为空)
		if((name!=null&&classGradeId!=null)&&(gradeId==null&&specialtyId==null&&collegeId==null&&schoolId==null)){
		PageInfo<Student> queryStudentByNameAndClassGradeWithPage;
		try {
			queryStudentByNameAndClassGradeWithPage = studentService.queryStudentByNameAndClassGradeWithPage(pageNum,
					pageSize, name, classGradeId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByNameAndClassGradeWithPage.getSize()<=0) {
				//根据名字和班级id查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
			//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList", queryStudentByNameAndClassGradeWithPage);
				return json;
		}
		//只班级id查询该班级学生
		if((classGradeId!=null)&&(name==null&&gradeId==null&&specialtyId==null&&collegeId==null&&schoolId==null)) {
		PageInfo<Student> queryClassGradeByClassGradeIdWithPage;
		try {
			queryClassGradeByClassGradeIdWithPage = studentService.queryClassGradeByClassGradeIdWithPage(pageNum, pageSize,
					classGradeId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryClassGradeByClassGradeIdWithPage.getSize()<=0) {
				//根据班级id查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryClassGradeByClassGradeIdWithPage);
				return json;
		}
		//姓名加年级
		if((name!=null&&gradeId!=null)&&(classGradeId==null&&specialtyId==null&&collegeId==null&&schoolId==null)) {
		PageInfo<Student> queryStudentByNameAndGradeWithPage;
		try {
			queryStudentByNameAndGradeWithPage = studentService.queryStudentByNameAndGradeWithPage(pageNum, pageSize, name,
					gradeId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByNameAndGradeWithPage.getSize()<=0) {
				//根据年级id和姓名查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryStudentByNameAndGradeWithPage);
				return json;
		}
		//仅年级查询
		if((gradeId!=null)&&(name==null&&classGradeId==null&&specialtyId==null&&collegeId==null&&schoolId==null)) {
			PageInfo<Student> queryStudentByGradeWithPage;
			try {
				queryStudentByGradeWithPage = studentService.queryStudentByGradeWithPage(pageNum, pageSize, gradeId);
			} catch (Exception e) {
					e.printStackTrace();
					json.put("status", -1);
					json.put("message", "服务器内部错误！");
					return json;
			}
				if(queryStudentByGradeWithPage.getSize()<=0) {
					//根据年级id查询出来页为空，则返回2该页为空。
					json.put("status", 2);
					json.put("message", "该页暂时没有学生！");
					return json;
				}
					//成功的操作
					json.put("status", 0);
					json.put("message", "操作成功！");
					json.put("studentList",queryStudentByGradeWithPage);
					return json;
		}
		//姓名加专业
		if((name!=null&&specialtyId!=null)&&(gradeId==null&&classGradeId==null&&collegeId==null&&schoolId==null)) {
		PageInfo<Student> queryStudentByNameAndSpecialtyWithPage;
		try {
			queryStudentByNameAndSpecialtyWithPage = studentService.queryStudentByNameAndSpecialtyWithPage(pageNum,
					pageSize, name, specialtyId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByNameAndSpecialtyWithPage.getSize()<=0) {
					//根据专业id和名字查询出来页为空，则返回2该页为空。
					json.put("status", 2);
					json.put("message", "该页暂时没有学生！");
					return json;
			}
					//成功的操作
					json.put("status", 0);
					json.put("message", "操作成功！");
					json.put("studentList",queryStudentByNameAndSpecialtyWithPage);
					return json;
		}
		//仅专业
		if((specialtyId!=null)&&(name==null&&gradeId==null&&classGradeId==null&&collegeId==null&&schoolId==null)) {
		PageInfo<Student> queryStudentBySpecialtyWithPage;
		try {
			queryStudentBySpecialtyWithPage = studentService.queryStudentBySpecialtyWithPage(pageNum, pageSize,
					specialtyId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentBySpecialtyWithPage.getSize()<=0) {
					//根据专业id查询出来页为空，则返回2该页为空。
					json.put("status", 2);
					json.put("message", "该页暂时没有学生！");
					return json;
			}
					//成功的操作
					json.put("status", 0);
					json.put("message", "操作成功！");
					json.put("studentList",queryStudentBySpecialtyWithPage);
					return json;
		}
		//姓名加学院
		if((name!=null&&collegeId!=null)&&(gradeId==null&&specialtyId==null&&classGradeId==null&&schoolId==null)) {
		PageInfo<Student> queryStudentByNameAndCollegeWithPage;
		try {
			queryStudentByNameAndCollegeWithPage = studentService.queryStudentByNameAndCollegeWithPage(pageNum, pageSize,
					name, collegeId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByNameAndCollegeWithPage.getSize()<=0) {
				//根据学院id和姓名查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryStudentByNameAndCollegeWithPage);
				return json;
		}
		//仅学院
		if((collegeId!=null)&&(name==null&&gradeId==null&&specialtyId==null&&classGradeId==null&&schoolId==null)) {
		PageInfo<Student> queryStudentByCollegeWithPage;
		try {
			queryStudentByCollegeWithPage = studentService.queryStudentByCollegeWithPage(pageNum, pageSize, collegeId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByCollegeWithPage.getSize()<=0) {
				//根据学院id查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryStudentByCollegeWithPage);
				return json;
		}
		//姓名加学校
		if((name!=null&&schoolId!=null)&&(gradeId==null&&specialtyId==null&&classGradeId==null&&collegeId==null)) {
		PageInfo<Student> queryStudentByNameAndSchoolWithPage;
		try {
			queryStudentByNameAndSchoolWithPage = studentService.queryStudentByNameAndSchoolWithPage(pageNum, pageSize,
					name, schoolId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentByNameAndSchoolWithPage.getSize()<=0) {
				//根据学校id和名字查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryStudentByNameAndSchoolWithPage);
				return json;
		}
		//仅学校
		if((schoolId!=null)&&(name==null&&gradeId==null&&specialtyId==null&&classGradeId==null&&collegeId==null)) {
		PageInfo<Student> queryStudentBySchoolWithPage;
		try {
			queryStudentBySchoolWithPage = studentService.queryStudentBySchoolWithPage(pageNum, pageSize, schoolId);
		} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
		}
			if(queryStudentBySchoolWithPage.getSize()<=0) {
				//根据学校id查询出来页为空，则返回2该页为空。
				json.put("status", 2);
				json.put("message", "该页暂时没有学生！");
				return json;
			}
				//成功的操作
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentList",queryStudentBySchoolWithPage);
				return json;
		}else {
				json.put("status", 3);
				json.put("message", "参数类型不匹配！");
				return json;
		}
	}
	/**
	 * @describe 根据公司id查询该公司的所有学生名字集合然后分页显示
	 * @param pageNum 页号
	 * @param pageSize 每页显示大小
	 * @param companyId 公司id
	 * @return
	 */
	@RequestMapping(value="queryStudentByCompany" ,method = RequestMethod.GET)  
	@ResponseBody
	public JSONObject queryStudentByCompany(Integer pageNum,Integer pageSize,String companyId) {
		JSONObject json=new JSONObject();
		if(pageNum==null||pageSize==null||companyId==null||"".equals(companyId)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		Company queryCompanyByCompanyId;
		try {
			queryCompanyByCompanyId = companyMapper.queryCompanyByCompanyId(companyId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if(queryCompanyByCompanyId==null) {
			json.put("status", 2);
			json.put("message", "该公司不存在！");
			return json;
		}
		PageInfo<Student> queryStudentByCompanyWithPage;
		try {
			queryStudentByCompanyWithPage = studentService.queryStudentByCompanyWithPage(pageNum, pageSize, companyId);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
		if(queryStudentByCompanyWithPage.getSize()<=0) {
			json.put("status", 3);
			json.put("message", "该页暂时没有学生！");
			return json;
		}
		//返回查询结果
			json.put("status", 0);
			json.put("message", "操作成功！");
			json.put("studentList",queryStudentByCompanyWithPage);
			return json;
		}
	/**
	 * @describe 根据教师工号查询教师所管理的班级、班级所在年级专业学院学校
	 * @param tno
	 *            教师工号
	 * @return
	 */
	@RequestMapping(value = "queryOneTeacherClassGradeInfoByTno", method = RequestMethod.GET)
	public JSONObject queryOneTeacherClassGradeInfoByTno(String tno) {
		JSONObject json = new JSONObject();
		if (tno == null || "".equals(tno)) {
			json.put("status", 1);
			json.put("message", "传入数据不合法!");
			return json;
		}
		// 数据处理
		// String tno;
		try {
			// tno = map.get("tno");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", 1);
			json.put("message", "传入数据不合法!");
			return json;
		}
		Teacher queryOneTeacherByTno;
		try {
			queryOneTeacherByTno = teacherMapper.queryOneTeacherByTno(tno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneTeacherByTno == null) {
			json.put("status", 2);
			json.put("message", "该教师不存在!");
			return json;
		}
		if ("refuse".equals(queryOneTeacherByTno.getRegisterStatus())) {
			json.put("status", 3);
			json.put("message", "该账号注册申请已被拒绝，请进行注册申请后再次进行操作!");
			return json;
		}
		if ("waiting".equals(queryOneTeacherByTno.getRegisterStatus())) {
			json.put("status", 4);
			json.put("message", "该账号申请正在审核中，管理员通过后方可进行操作!");
			return json;
		}
		Teacher queryOneTeacherInfoByTno;
		try {
			queryOneTeacherInfoByTno = teacherMapper.queryOneTeacherInfoByTno(tno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneTeacherInfoByTno.getClassGrades() == null) {
			json.put("status", 5);
			json.put("message", "该教师未管理任何班级!");
			return json;
		}
		json.put("status", 0);
		json.put("message", "操作成功!");
		json.put("teacher", queryOneTeacherInfoByTno);
		return json;
	}

	/**
	 * @describe 根据教师工号查询教师基本信息(电话邮箱姓名性别等等)
	 * @param tno
	 *            传入的教师工号
	 * @return
	 */
	@RequestMapping(value = "queryOneTeacherInfoByTno", method = RequestMethod.GET)
	public JSONObject queryOneTeacherInfoByTno(String tno) {
		JSONObject json = new JSONObject();
		if (tno == null || "".equals(tno)) {
			json.put("status", 1);
			json.put("message", "传入数据不合法！");
			return json;
		}
		// 数据处理
		// String tno;
		try {
			// tno = map.get("tno");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", 1);
			json.put("message", "传入数据不合法！");
			return json;
		}
		// 判断教师是否存在
		Teacher queryOneTeacherByTno;
		try {
			queryOneTeacherByTno = teacherMapper.queryOneTeacherByTno(tno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneTeacherByTno == null) {
			json.put("status", 2);
			json.put("message", "该教师不存在！");
			return json;
		}
		// //存在判断状态字段（refuse与waiting状态不能查询）
		// if("refuse".equals(queryOneTeacherByTno.getRegisterStatus())) {
		// json.put("status", 3);
		// json.put("message","该账号注册申请已被拒绝，请进行注册申请后再次进行操作!");
		// return json;
		// }
		// if("waiting".equals(queryOneTeacherByTno.getRegisterStatus())) {
		// json.put("status", 4);
		// json.put("message","该账号申请正在审核中，管理员通过后方可进行操作!");
		// return json;
		// }
		// 抹去密码信息
		queryOneTeacherByTno.setPassword(null);
		json.put("status", 0);
		json.put("message", "操作成功！");
		json.put("teacher", queryOneTeacherByTno);
		return json;
	}

	/**
	 * 教师注册时放发送验证邮件
	 * 
	 * @param email
	 *            邮箱
	 * @param session
	 *            session对象
	 * @return
	 */
	@RequestMapping(value = "sendEmail", method = RequestMethod.GET)
	public JSONObject sendEmail(String email, HttpSession session) {
		JSONObject json = new JSONObject();
		// 数据处理
		// String email;
		try {
			// email = map.get("email");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		// 查询是否有人使用
		Teacher queryOneTeacherByEmail;
		try {
			queryOneTeacherByEmail = teacherMapper.queryOneTeacherByEmail(email);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误");
			return json;
		}
		if (queryOneTeacherByEmail != null) {
			json.put("status", 2);
			json.put("message", "该邮箱已经有人使用！");
			return json;
		}
		// 校验邮箱格式
		boolean checkemail = MailUtil.checkemail(email);
		if (checkemail == false) {
			json.put("status", 3);
			json.put("message", "您输入的邮箱格式不正确，请输入正确的邮箱格式！");
			return json;
		}
		// 产生随机码
		String checkCode = CheckcodeUtil.getCheckCode();
		// 将其放入session
		session.setAttribute("checkCode", checkCode);
		// 发送邮件
		MailUtil.send(email, "[实习系统]实习系统验证邮件", "[实习系统]尊敬的教师您好:感谢您使用实习系统，您的验证码是:" + checkCode + "。");
		json.put("status", 0);
		json.put("message", "验证码发送成功，请至邮箱进行查收！");
		return json;
	}
	/**
	 * 
	 * @param pageNum 从第几页开始查询
	 * @param pageSize 页面大小
	 * @param tno 教师编号
	 * @param flag =1查询实习集合 =0查询未实习人的集合
	 * @return
	 */
	@RequestMapping(value="queryStudentWithNoInternship" ,method = RequestMethod.GET)  
	@ResponseBody
	public JSONObject queryStudentWithNoInternship(Integer pageNum,Integer pageSize,String tno,Integer flag) {
		JSONObject json=new JSONObject();
		//数据校验
		if(pageNum==null||pageSize==null||tno==null||"".equals(tno)) {
			json.put("status", 1);
			json.put("message", "传入参数不合法！");
			return json;
		}
		//对flag进行判断:1查实习的人,0未实习的人
		if(flag==1) {
		PageInfo<Student> queryStudentWithInternshipWithPage;
		try {
			queryStudentWithInternshipWithPage = studentService.queryStudentWithInternshipWithPage(pageNum, pageSize, tno);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "服务器内部错误！");
			return json;
		}
			if(queryStudentWithInternshipWithPage.getSize()<=0){
				json.put("status", 2);
				json.put("message", "该页没有学生！");
				return json;
			}
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentlist", queryStudentWithInternshipWithPage);
				return json;
		}else {//0未实习的人
			PageInfo<Student> queryStudentWithNoInternshipWithPage;
			try {
				queryStudentWithNoInternshipWithPage = studentService.queryStudentWithNoInternshipWithPage(pageNum, pageSize, tno);
			} catch (Exception e) {
				e.printStackTrace();
				json.put("status", -1);
				json.put("message", "服务器内部错误！");
				return json;
			}
			if(queryStudentWithNoInternshipWithPage.getSize()<=0){
				json.put("status", 2);
				json.put("message", "该页没有学生！");
				return json;
			}
				json.put("status", 0);
				json.put("message", "操作成功！");
				json.put("studentlist", queryStudentWithNoInternshipWithPage);
				return json;
			}
		}
	/*
	 * 学生查看单个通知
	 */
	@PostMapping("inform/selectInformById")
	public JSONObject selectInformById(@RequestBody Map<String, String> map, HttpSession session) {
		JSONObject json = new JSONObject();
		String account = map.get("account");
		String informID = map.get("informID");
		int status = -1;
		String message = "网络有点慢，请重试";
		Inform inform = informService.selectInformByIda(informID);
		Feedback feedback = feedbackService.selectFeedbackBySnoAndId(account, informID);
		if (feedback != null) {
			status = 200;
			message = "内容马上来,请稍后...";
			json.put("inform", inform);
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		// }
		if (inform != null) {// 查看文档成功

			status = 200;
			message = "内容马上来,请稍后...";
		}
		json.put("inform", inform);
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 老师查看单个通知
	 */
	@PostMapping("inform/selectInformByIdByTno")
	public JSONObject selectInformByIdByTno(@RequestBody Map<String, String> map, HttpSession session) {
		JSONObject json = new JSONObject();
		int status = -1;
		String message = "网络有点慢，请重试";
		String informID = map.get("informID");
		Inform inform = informService.selectInformById(informID);// 根据通知id找到通知对象
		if (inform != null) {// 查看文档成功

			status = 200;
			message = "内容马上来,请稍后...";
		}
		json.put("inform", inform);
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 学生查看通知列表（前端需要通知标题，通知标号，通知的概要内容，通知发布的时间，该学生是否已读）
	 * 流程：从session得到学生的学号id，然后根据学号查询学生表，得到学生表里面的老师工号
	 * 根据老师工号查看通知表，得到所有该老师所有的通知对象（通知对象包含通知标号，标题，内容，发布时间）
	 * 根据学生的学号id，去查询中间表feedback，得到该学生已读通知的编号id 用学生已读通知的编号和老师发布所有通知的编号比对，得出是否已读
	 */
	@PostMapping("inform/selectInformList")
	public JSONObject selectInformList(@RequestBody String id) {
		JSONObject json = JSONObject.parseObject(id);
		String ids = json.getString("id");
		int status = 200;
		String message = "网络正在快马加鞭...";

		// String id = (String) session.getAttribute("account");
		List<Inform> inform = null;

		try {
			inform = informService.selectInformIdByTnoBySno(ids);// 得到该学生的老师的通知
		} catch (Exception e) {
			e.printStackTrace();
		}
		List<Feedback> studentInformId = feedbackService.selectFeedbackBySno(ids);// 得到该学生已读通知
		String iid = null;
		String fid = null;

		for (int i = 0; i < studentInformId.size(); i++) {

			fid = studentInformId.get(i).getInform().getInformId();
			for (Inform n : inform) {
				iid = n.getInformId();
				if (fid.equals(iid)) {
					n.setFeedbacks(studentInformId);
				}
			}
		}
		json.put("list", inform);
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 老师查看通知列表
	 */
	@PostMapping("inform/selectInformListByTno")
	public JSONObject selectInformListByTno(@RequestBody Map<String, String> map) {
		JSONObject json = new JSONObject();
		int status = 200;
		String message = "网络正在快马加鞭...";

		String id = map.get("account");
		List<Inform> inform = informService.selectInformByTno(id);
		if (inform.size() < 1) {
			status = -1;
			message = "您还没有发布通知";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		int number = feedbackService.selectStudentConut(id);// 该老师带学生的人数
		List<Integer> readNumbers = new ArrayList<>();// 未读人数的集合
		int readNumber = 0;
		for (int i = 0; i < inform.size(); i++) {
			readNumber = feedbackService.selectById(inform.get(i).getInformId());// 已读人数
			readNumbers.add(number - readNumber);
		}
		json.put("readNumbers", readNumbers);
		json.put("list", inform);
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 老师查看某条通知的未读名单
	 */
	@PostMapping("selectFeedbackRead")
	public JSONObject selectFeedbackById(@RequestBody Map<String, String> map) {
		JSONObject json = new JSONObject();
		int status = 200;
		String message = "网络正在快马加鞭...";
		 String informId = map.get("informId");
		 String id = map.get("account");
		List<Feedback> list = feedbackService.selectFeedbckById(informId);// 得到已读学生的信息
		List<Student> liststudent = feedbackService.selectStudent(id);
		String listId;
		String studentid;
		for (int i = 0; i < list.size(); i++) {
			listId = list.get(i).getStudent().getSno();
			for (int j = 0; j < liststudent.size(); j++) {

				studentid = liststudent.get(j).getSno();
				if (studentid.equals(listId)) {

					liststudent.remove(j);
					continue;
				}
			}
		}

		json.put("list", liststudent);
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/*
	 * 获取公司列表
	 */
	@GetMapping("company/selectList")
	public JSONObject selectCompanyList() {
		JSONObject json = new JSONObject();
		int status = -1;
		String message = "网络延迟，请重试";
		List<Company> list = new ArrayList<>();
		try {
			list = companyService.selectComanyList();
		} catch (Exception e) {
			e.printStackTrace();
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		if (list.size() > 0) {
			status = 200;
			message = "内容马上来";
			json.put("list", list);
		}
		json.put("status", status);
		json.put("message", message);
		return json;
	}

	/**
	 * 查看单个评论
	 * 
	 * @param companyId
	 * @param sno
	 * @param content
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "comment/selectComment", method = RequestMethod.POST)
	@ResponseBody
	public JSONObject selectComment(@RequestBody Map<String, String> map, HttpSession session) {

		JSONObject json = new JSONObject();
		String commentId = map.get("commentId");
		try {
			Comment comment = commentService.findCommentByCommentId(commentId);
			if (comment != null) {
				json.put("status", 0);
				json.put("message", "查询成功");
				session.setAttribute("selectComment", comment);
				json.put("comment", comment);
			} else {
				json.put("status", -1);
				json.put("message", "查询失败");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "查询失败!");
			return json;
		}
		return json;
	}

	/**
	 * 分页查询评论
	 * 
	 * @param companyId
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@RequestMapping(value = "comment/findCommentByCompany", method = RequestMethod.POST)
	@ResponseBody
	public JSONObject findCommentByCompany(@RequestBody Map<String, Object> map) {
		int status = -1;
		JSONObject json = new JSONObject();
		String companyId = (String) map.get("companyId");
		int pageNum = (int) map.get("pageNum");
		int pageSize = (int) map.get("pageSize");
		try {
			PageHelper.startPage(pageNum, pageSize);
			List<Comment> list = commentService.findCommentByCompany(companyId, pageNum, pageSize);
			if (list.size() != 0) {
				status = 1;
				PageInfo<Comment> pageInfo = new PageInfo<Comment>(list);
				json.put("pageInfo", pageInfo);
				json.put("status", status);
				json.put("message", "分页查询成功");
			} else {
				status = -2;
				json.put("list", list);
				json.put("status", status);
				json.put("message", "当前该公司没有评论");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "分页查询失败");
			return json;
		}
		return json;
	}
	/**
	 * 通过学生和公司查询是否有实习记录
	 * 有才能对其进行发表评论
	 * @param sno
	 * @param companyId
	 * @return
	 */
	@RequestMapping(value="comment/findPracticeByStudentAndCompany",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject findPracticeByStudentAndCompany(@RequestBody Map<String, String> map){		
		int status=-1;
		JSONObject json = new JSONObject();
		String sno=map.get("sno");
		String companyId=map.get("companyId");
		 try {
			List<Practice> list = commentService.findPracticeByStudentAndCompany(sno, companyId);
			 if (list.size()==0) {
				status=0;
				json.put("message", "没在当前公司工作过,无法进行评论");
				json.put("status", status);			
			}
			 else {
					status=1;
					json.put("message", "允许评论");
					json.put("status", status);		
				}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "不允许评论");
			return json;	
		}	
		return json;		
	}
	/*
	 * 根据公司id获取公司图片
	 */
	@PostMapping("selectCompanyImgById")
	@ResponseBody
	public JSONObject selectCompanyImgById(@RequestBody Map<String, String> map){
		JSONObject json=new JSONObject();
		int status=1;
		String companyId = map.get("companyId");
		System.out.println(companyId+"111");
		String message="当前公司还没有图片";
		
		if(companyId==null||companyId.equals("")){
			message="公司id为空";
			json.put("status", -1);
			json.put("message", message);
			return json;	
		}
		String[] img = null;
		try {
			img = companyService.selectCompanyImgById(companyId);
		} catch (Exception e) {
			e.printStackTrace();
			status=-1;
			message="查询失败";
			json.put("status", status);
			json.put("message", message);
			return json;
		}
		if(img!=null&&img.length>0){
			status=200;
			message="当前公司有"+img.length+"张图片";
			json.put("img", img);
		}
		json.put("status", status);
		json.put("message", message);
		return json;
	}
	/**
	 * 分页查看个人发布的评论
	 * @param companyId
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@RequestMapping(value="comment/findCommentByCompanyAndSno",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject findCommentByCompanyAndSno(@RequestBody Map<String, Object> map){
		int status=-1;	
		JSONObject json = new JSONObject();	 
		String sno =(String) map.get("sno");
		String companyId = (String) map.get("companyId");
		int pageNum = (int) map.get("pageNum");
		int pageSize = (int) map.get("pageSize");
		try {
			PageHelper.startPage(pageNum, pageSize);	 
			List<Comment> list = commentService.findCommentByCompanyAndSno(sno, companyId, pageSize, pageNum);     
			if (list.size()!=0) {
			   status=1;
			   PageInfo<Comment> pageInfo = new PageInfo<Comment>(list);
			   json.put("pageInfo", pageInfo);
			   json.put("status", status);
			   json.put("message", "分页查询成功");
				}
			else if (list.size()==0) {
				   status=-2;
				   json.put("status", status);
				   json.put("message", "当前你没在当前公司发布评论，请添加评论");
			}
			else{
			   status=0;
			   json.put("status", status);
			   json.put("message", "分页查询失败");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			json.put("status", -1);
			json.put("message", "分页查询失败");
			return json;	
		}
		return json;		
	}
	
}